package com.xyazm.core.common;

import java.util.concurrent.*;

/**
 * @author xuyou
 * @date 2022年12月27日 21:49
 */
public class CustomExecutorService {


    private final static ExecutorService threadPoolExecutor = new ThreadPoolExecutor(1, 100,
            60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new UpdateThreadFactory());


    public static ExecutorService getCustomExecutorService() {
        return threadPoolExecutor;
    }


    public static class UpdateThreadFactory implements ThreadFactory {
        private static int threadInitNumber = 0;

        private static synchronized int nextThreadNum() {
            return threadInitNumber++;
        }

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "Thread-Segment-Update-" + nextThreadNum());
        }
    }
}
